package itcz.example.pattern.create_action.singleton.demo9;

import java.lang.reflect.Constructor;

/**
 * @ClassName: Client
 * @Author: ITCZ
 * @Date: 2025-04-21
 * @Description: 反射方式破坏单例模式
 */
public class Client {
    public static void main(String[] args) throws Exception {
        // 1. 获取Singleton类的字节码对象
        Class clazz = Singleton.class;
        // 2.获取无参构造器
        Constructor constructor = clazz.getDeclaredConstructor();
        // 3.取消访问检查
        constructor.setAccessible(true);
        // 4.反射方式构建对象
        Singleton singleton1 = (Singleton) constructor.newInstance();
        Singleton singleton2 = (Singleton) constructor.newInstance();
        System.out.println(singleton1 == singleton2);
    }

}
